﻿using System;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Design;
using System.ComponentModel;
using System.Collections.Generic;
using System.Windows.Forms.Design;
using SedionFormDesigner.CusControls.DataGridView;
using SedionFormDesigner.Infrastructure;

namespace SedionFormDesigner.CusControls.TypeEditor
{
    public class DataBindingEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            if (context != null && context.Instance != null)
            {
                return UITypeEditorEditStyle.Modal;
            }
            return base.GetEditStyle(context);
        }

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService editorService = null;
            BD_DataGridView grdView = new BD_DataGridView();
            CustomProperty cp = context.Instance as CustomProperty;
            if (cp != null)
                grdView = cp.GetCurrentSelectObject() as BD_DataGridView;

            if (context != null && context.Instance != null)
            {
                editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if (editorService != null)
                {
                    FrmAddData frmAddData = new FrmAddData(grdView);
                    if (frmAddData.ShowDialog() == DialogResult.OK)
                    {
                        value = frmAddData.GetDataGridView();
                    }
                    return value;
                }
            }

            return base.EditValue(context, provider, value);
        }
    }
}
